/**
 * 
 */
package app.tuwien.isi.tweetanalyser;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author Philipp Pospisil
 *
 */
public class StatisticAdapter extends BaseAdapter {

	private final List<Statistic> statistic;
    private LayoutInflater statisticInflater;
    
    public StatisticAdapter(Context context, List<Statistic> statistic) {
        this.statistic = statistic;

        statisticInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    
    public int getCount() {
        return statistic.size();
    }
	public long getItemId(int position) {
		return position;
	}
    public Object getItem(int position) {
        return statistic.get(position);
    }
    public String getItemCategory(int position) {
        return statistic.get(position).getCategory();
    }
    public int getItemLengthOfList(int position) {
        return statistic.get(position).getLengthOfList();
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
    	Statistic stat = (Statistic) getItem(position);	
        
    	ViewHolder holder;
        
        if(convertView == null) {
        	convertView = statisticInflater.inflate(R.layout.statistic_item, parent, false);

        	holder = new ViewHolder(); 
        	holder.textCategory = (TextView) convertView.findViewById(R.id.categoryText); 
   		 	holder.textSum = (TextView) convertView.findViewById(R.id.sumText); 
   		 	
   		 	convertView.setTag(holder); 
        } else {
        	holder = (ViewHolder) convertView.getTag(); 
        }

        holder.textCategory.setText(stat.getCategory()); 
        holder.textSum.setText("" + stat.getLengthOfList());
        
        return convertView;
    }
    
    public static class ViewHolder {
        public TextView textCategory;
        public TextView textSum;
    }
}
